Skip to content

[fix](fs) Make PathUtils.equalsIgnoreSchemeIfOneIsS3 path comparison consistent#64768

Draft
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:fix/pathutils-s3-scheme-consistency
Draft

[fix](fs) Make PathUtils.equalsIgnoreSchemeIfOneIsS3 path comparison consistent#64768
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:fix/pathutils-s3-scheme-consistency

Conversation

@LuciferYang

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: close #64767

Problem Summary:

PathUtils.equalsIgnoreSchemeIfOneIsS3(p1, p2) (used by HMSTransaction to decide whether a Hive commit needs a rename) compared paths inconsistently across its two branches:

  • same scheme → full-string equalsIgnoreCase (trailing slash significant, case-insensitive);
  • cross-scheme with s3 → normalized authority+path via Objects.equals (trailing slash stripped, case-sensitive).

So the result for one URI depended on the other URI's scheme, and same-scheme comparisons wrongly ignored case (S3 keys are case-sensitive).

This PR unifies both branches into one rule: when the schemes are equal (case-insensitively, per RFC 3986 §3.1) or one side is s3, compare only the authority (bucket/host) and path — scheme ignored, trailing slashes insignificant, case-sensitive on the raw (percent-encoded) components; otherwise the locations are not equal. This matches the original normalize() intent and the caller's "no rename when the location is identical" comment, and applies the slash/case handling consistently regardless of whether the two schemes match.

Inputs that are malformed for object storage fall back to exact string comparison so they cannot spuriously match: opaque URIs (s3:bucket/key), scheme-with-null-authority triple-slash forms (s3:///path), authority-with-null-scheme network-path references (//bucket/path), and parse failures. Percent-encoded slashes (%2F) stay distinct from real path separators.

The change was hardened via a multi-persona adversarial review loop run to convergence (5 consecutive clean rounds); the extra rounds mainly added test coverage.

Release note

None

Check List (For Author)

  • Test

    • Unit Test (PathUtilsTest, 23 cases covering the consistency contract plus opaque/encoded/triple-slash/network-path/null/scheme-family edge cases)
  • Behavior changed:

    • Yes. equalsIgnoreSchemeIfOneIsS3 now treats trailing slashes as insignificant and the authority+path comparison as case-sensitive consistently for same-scheme and cross-scheme inputs. For realistic fully-qualified Hive S3/OSS locations the rename decision is unchanged; the difference only appears for trailing-slash-only or case-only differences and for malformed inputs.
  • Does this need documentation?

    • No.

…consistent

equalsIgnoreSchemeIfOneIsS3 used inconsistent logic across its two branches: same-scheme did a full-string case-INsensitive compare with the trailing slash significant, while cross-scheme (one is s3) compared normalized authority+path case-sensitively with the trailing slash stripped. The result for one URI therefore depended on the other URI's scheme, and same-scheme comparisons wrongly ignored case (S3 keys are case-sensitive).

Unify both branches into one rule: when schemes are equal (case-insensitively) or one side is s3, compare the authority and path only, with trailing slashes insignificant and the comparison case-sensitive on the raw (percent-encoded) components; otherwise not equal. This matches the original normalize() intent and the sole caller HMSTransaction (avoid renames when the location is identical). Malformed inputs for object storage (opaque URIs, scheme-with-null-authority triple-slash forms, authority-with-null-scheme network-path references, parse failures) fall back to exact string comparison; percent-encoded slashes stay distinct. Hardened via multi-persona review; adds extensive PathUtilsTest coverage.
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PathUtils.equalsIgnoreSchemeIfOneIsS3 path comparison is inconsistent between same-scheme and cross-scheme branches

2 participants